package com.zyf.project.binaryproto.common;

import com.zyf.project.binaryproto.contract.DataContractEncoder;
import com.zyf.project.binaryproto.contract.impl.DataContractContext;

import java.util.function.Function;

/**
 * <h1>数据契约的注册器</h1>
 *
 * @author Zhou Yifan
 */
public class DataContractRegistry {

    private static final DataContractContext CONTEXT = new DataContractContext();

    DataContractRegistry() {
    }

    private static void autoRegister() {
        //
    }

    public static DataContractEncoder register(Class<?> contractType) {
        return register(contractType, null);
    }

    public static DataContractEncoder register(Class<?> contractType, Function<Integer, ?> arrayConstructor) {
        return CONTEXT.register(contractType, arrayConstructor);
    }

    public static DataContractEncoder getEncoder(Class<?> contractType) {
        return CONTEXT.lookup(contractType);
    }

    public static DataContractEncoder getEncoder(int code, long version) {
        return CONTEXT.lookup(code, version);
    }

}
